//
//  DARateView.m
//  DAKnowledge
//
//  Created by DreamArts on 16/5/20.
//  Copyright © 2016年 lidongyang. All rights reserved.
//

#import "DARateView.h"

@interface DARateView (){
    UIImageView *rateImage1;
    UIImageView *rateImage2;
    UIImageView *rateImage3;
    UIImageView *rateImage4;
    UIImageView *rateImage5;
}
@end

@implementation DARateView


- (instancetype)initWithFrame:(CGRect)frame Rate:(NSInteger)rateNum{
    self = [super initWithFrame:frame];
    if(self){
        rateNumber = rateNum;
        self.backgroundColor = [UIColor clearColor];
        
       // [self creatImageView];
    }
    return self;
}

- (void)rateNum:(NSInteger)num{
    rateNumber = num;
    //NSLog(@"%ld几个星", num);
    [self creatImageView];
    if(num == 0 || num < 0){
        rateImage1.image = [UIImage imageNamed:@"rate0"];
        rateImage2.image = [UIImage imageNamed:@"rate0"];
        rateImage3.image = [UIImage imageNamed:@"rate0"];
        rateImage4.image = [UIImage imageNamed:@"rate0"];
        rateImage5.image = [UIImage imageNamed:@"rate0"];
    }else if (num == 1){
        rateImage1.image = [UIImage imageNamed:@"rate1"];
        rateImage2.image = [UIImage imageNamed:@"rate0"];
        rateImage3.image = [UIImage imageNamed:@"rate0"];
        rateImage4.image = [UIImage imageNamed:@"rate0"];
        rateImage5.image = [UIImage imageNamed:@"rate0"];
    }else if (num == 2){
        rateImage1.image = [UIImage imageNamed:@"rate1"];
        rateImage2.image = [UIImage imageNamed:@"rate1"];
        rateImage3.image = [UIImage imageNamed:@"rate0"];
        rateImage4.image = [UIImage imageNamed:@"rate0"];
        rateImage5.image = [UIImage imageNamed:@"rate0"];
    }else if (num == 3){
        rateImage1.image = [UIImage imageNamed:@"rate1"];
        rateImage2.image = [UIImage imageNamed:@"rate1"];
        rateImage3.image = [UIImage imageNamed:@"rate1"];
        rateImage4.image = [UIImage imageNamed:@"rate0"];
        rateImage5.image = [UIImage imageNamed:@"rate0"];
    }else if (num == 4){
        rateImage1.image = [UIImage imageNamed:@"rate1"];
        rateImage2.image = [UIImage imageNamed:@"rate1"];
        rateImage3.image = [UIImage imageNamed:@"rate1"];
        rateImage4.image = [UIImage imageNamed:@"rate1"];
        rateImage5.image = [UIImage imageNamed:@"rate0"];
    }else if (num == 5 || num > 5){
        rateImage1.image = [UIImage imageNamed:@"rate1"];
        rateImage2.image = [UIImage imageNamed:@"rate1"];
        rateImage3.image = [UIImage imageNamed:@"rate1"];
        rateImage4.image = [UIImage imageNamed:@"rate1"];
        rateImage5.image = [UIImage imageNamed:@"rate1"];
    }

}
- (void)creatImageView{
    
    if (rateImage1) {
        
    }else{
        rateImage1 = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 12, 12)];
        rateImage1.layer.shouldRasterize = YES;
        rateImage1.layer.rasterizationScale = 2;
        [self addSubview:rateImage1];
    }
    
    if (rateImage2) {
        
    }else{
        rateImage2 = [[UIImageView alloc]initWithFrame:CGRectMake(13, 0, 12, 12)];
        rateImage2.layer.shouldRasterize = YES;
        rateImage2.layer.rasterizationScale = 2;
        [self addSubview:rateImage2];
    }
    
    if (rateImage3) {
        
    }else{
        rateImage3 = [[UIImageView alloc]initWithFrame:CGRectMake(26, 0, 12, 12)];
        rateImage3.layer.shouldRasterize = YES;
        rateImage3.layer.rasterizationScale = 2;
        [self addSubview:rateImage3];
    }
    
    if (rateImage4) {
        
    }else{
        rateImage4 = [[UIImageView alloc]initWithFrame:CGRectMake(39, 0, 12, 12)];
        rateImage4.layer.shouldRasterize = YES;
        rateImage4.layer.rasterizationScale = 2;
        [self addSubview:rateImage4];
    }
    
    if (rateImage5) {
        
    }else{
        rateImage5 = [[UIImageView alloc]initWithFrame:CGRectMake(52, 0, 12, 12)];
        rateImage5.layer.shouldRasterize = YES;
        rateImage5.layer.rasterizationScale = 2;
        [self addSubview:rateImage5];
    }
    
    
}

//- (void)drawRect:(CGRect)rect{
//    [super drawRect:rect];
//    rateImage1 = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 12, 12)];
//    rateImage2 = [[UIImageView alloc]initWithFrame:CGRectMake(13, 0, 12, 12)];
//    rateImage3 = [[UIImageView alloc]initWithFrame:CGRectMake(26, 0, 12, 12)];
//    rateImage4 = [[UIImageView alloc]initWithFrame:CGRectMake(39, 0, 12, 12)];
//    rateImage5 = [[UIImageView alloc]initWithFrame:CGRectMake(52, 0, 12, 12)];
//    rateImage1.layer.shouldRasterize = YES;
//    rateImage1.layer.rasterizationScale = 2;
//    rateImage2.layer.shouldRasterize = YES;
//    rateImage2.layer.rasterizationScale = 2;
//    rateImage3.layer.shouldRasterize = YES;
//    rateImage3.layer.rasterizationScale = 2;
//    rateImage4.layer.shouldRasterize = YES;
//    rateImage4.layer.rasterizationScale = 2;
//    rateImage5.layer.shouldRasterize = YES;
//    rateImage5.layer.rasterizationScale = 2;
//    [self addSubview:rateImage1];
//    [self addSubview:rateImage2];
//    [self addSubview:rateImage3];
//    [self addSubview:rateImage4];
//    [self addSubview:rateImage5];
//    
//    NSLog(@"\\\\\\\\\%ld", rateNumber);
//    
//    if(rateNumber == 0 || rateNumber < 0){
//        rateImage1.image = [UIImage imageNamed:@"rate0"];
//        rateImage2.image = [UIImage imageNamed:@"rate0"];
//        rateImage3.image = [UIImage imageNamed:@"rate0"];
//        rateImage4.image = [UIImage imageNamed:@"rate0"];
//        rateImage5.image = [UIImage imageNamed:@"rate0"];
//    }else if (rateNumber == 1){
//        rateImage1.image = [UIImage imageNamed:@"rate1"];
//        rateImage2.image = [UIImage imageNamed:@"rate0"];
//        rateImage3.image = [UIImage imageNamed:@"rate0"];
//        rateImage4.image = [UIImage imageNamed:@"rate0"];
//        rateImage5.image = [UIImage imageNamed:@"rate0"];
//    }else if (rateNumber == 2){
//        rateImage1.image = [UIImage imageNamed:@"rate1"];
//        rateImage2.image = [UIImage imageNamed:@"rate1"];
//        rateImage3.image = [UIImage imageNamed:@"rate0"];
//        rateImage4.image = [UIImage imageNamed:@"rate0"];
//        rateImage5.image = [UIImage imageNamed:@"rate0"];
//    }else if (rateNumber == 3){
//        rateImage1.image = [UIImage imageNamed:@"rate1"];
//        rateImage2.image = [UIImage imageNamed:@"rate1"];
//        rateImage3.image = [UIImage imageNamed:@"rate1"];
//        rateImage4.image = [UIImage imageNamed:@"rate0"];
//        rateImage5.image = [UIImage imageNamed:@"rate0"];
//    }else if (rateNumber == 4){
//        rateImage1.image = [UIImage imageNamed:@"rate1"];
//        rateImage2.image = [UIImage imageNamed:@"rate1"];
//        rateImage3.image = [UIImage imageNamed:@"rate1"];
//        rateImage4.image = [UIImage imageNamed:@"rate1"];
//        rateImage5.image = [UIImage imageNamed:@"rate0"];
//    }else if (rateNumber == 5 || rateNumber > 5){
//        rateImage1.image = [UIImage imageNamed:@"rate1"];
//        rateImage2.image = [UIImage imageNamed:@"rate1"];
//        rateImage3.image = [UIImage imageNamed:@"rate1"];
//        rateImage4.image = [UIImage imageNamed:@"rate1"];
//        rateImage5.image = [UIImage imageNamed:@"rate1"];
//    }
//    
//}




@end
